$(function () {
    obj.init();
});
var obj = new function () {
    'use strict';
    return {
        boxFileList: null,
        mac: null,
        url: null,
        tag: null,
        type: null,
        page: 1,
        init: function () {
            this.mac = xhTool.getQuery('mac');
            this.boxFileList = new xhDataGrid($('#boxFileList'), 'box/getBoxFileList',{'mac':this.mac});
            this.boxFileList.parseToolbar().init();
            this.funObj().initSelectMac();
            this.listener();
        },
        listener: function () {
            var $this = this;

            //搜索
            $('#bt_search').click(function () {
                $this.mac = $('#macId').val();
                $this.url = $('#downUrl').val();
                $this.type = $('#businessType').val();
                $this.tag = $('#tag').val();
                $this.funObj().searchList();
            });
            $this.boxFileList.onLoadSuccess = function () {
                $this.funObj().formatterBusinessType();
            };
            //上一页
            $('#prePage').click(function () {
                $this.funObj().prevPage();
            });
            //下一页
            $('#nextPage').click(function () {
                $this.funObj().nextPage();
            });
        },
        funObj: function () {
            var $this = this;
            return {
                searchList: function () {
                    $this.boxFileList.reload({mac: $this.mac, url: $this.url, tag: $this.tag, type:$this.type});
                },
                initSelectMac: function () {
                    $('#macId').combobox({
                        url:'getMacList',
                        valueField:'mac',
                        textField:'schoolName'
                    });
                    $('#macId').combobox('setValue', $this.mac);

                },
                formatterBusinessType: function () {
                    $('td[field="type"] div').each(function (index,element) {
                       var type = $(this).text();
                        $(this).text(business_type[type]);
                    });
                },
                prevPage: function () {
                    if ($this.page > 1) {
                        $this.page = $this.page-1;
                    }
                    $this.boxFileList.reload({mac: $this.mac, url: $this.url, page: $this.page, tag: $this.tag, type:$this.type});
                },
                nextPage: function () {
                    $this.page = $this.page+1;
                    $this.boxFileList.reload({mac: $this.mac, url: $this.url, page: $this.page, tag: $this.tag, type:$this.type});
                }
            }
        }
    }
}
